<template>
	<xn-form-container
		:title="formData.id ? '编辑审核管理' : '增加审核管理'"
		:width="700"
		:visible="visible"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-row :gutter="16">
				<a-col :span="12">
					<a-form-item label="审核名称：" name="auditReportName">
						<a-input v-model:value="formData.auditReportName" placeholder="请输入审核名称" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="12">
					<a-form-item label="结论：" name="resultSummary">
						<a-input v-model:value="formData.resultSummary" placeholder="请输入结论" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="12" v-show="!qoneProjectId">
					<a-form-item label="项目ID：" name="projectId">
						<a-input v-model:value="formData.projectId" placeholder="请输入项目ID" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="12">
					<a-form-item label="审核负责人：" name="principal">
						<a-input v-model:value="formData.principal" placeholder="请输入审核负责人" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="12">
					<a-form-item label="扩展信息：" name="extJson">
						<a-input v-model:value="formData.extJson" placeholder="请输入扩展信息" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="12">
					<a-form-item label="密级：" name="secLevel">
						<a-input v-model:value="formData.secLevel" placeholder="请输入密级" allow-clear />
					</a-form-item>
				</a-col>
			</a-row>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="qoneAuditReportForm">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import qoneAuditReportApi from '@/api/pm/qoneAuditReportApi'
	import {globalStore} from "@/store";
	const store = globalStore()
	const qoneProjectId = store.projectId
	// 抽屉状态
	const visible = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)

	// 打开抽屉
	const onOpen = (record) => {
		visible.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}else {

			formData.value.projectId = qoneProjectId
		}
	}
	// 关闭抽屉
	const onClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		visible.value = false
	}
	// 默认要校验的
	const formRules = {
	}
	// 验证并提交数据
	const onSubmit = () => {
		formRef.value.validate().then(() => {
			submitLoading.value = true
			const formDataParam = cloneDeep(formData.value)
			qoneAuditReportApi
				.qoneAuditReportSubmitForm(formDataParam, formDataParam.id)
				.then(() => {
					onClose()
					emit('successful')
				})
				.finally(() => {
					submitLoading.value = false
				})
		})
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
